package com.shj.util;


import org.apache.commons.beanutils.BeanUtils;

import java.util.HashMap;
import java.util.Map;

/**
 * @author songhuajian
 * @Description: TODO
 * @date 2020/6/6 19:36
 **/
public class MapUtil {

    /**
     * @Description 对象转map
     * @author songhuajian
     * @date 2020/6/6 19:36
     */
    public static Map<String, String> objectToMap(Object obj) throws IllegalAccessException{
        try {
            if(obj instanceof Map){
                return (Map<String, String>)obj;
            }
            Map<String, String> map = BeanUtils.describe(obj);
            map.remove("class");
            return map;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return new HashMap<String, String>();
    }
}
